/*
 * 通知公告
 * @author      zhul
 * @createdate  2017-04-24
 */

if (typeof BusNotice !== 'object') {
    var BusNotice = {};
}

(function (window, undefined) {

    // 初始化
    BusNotice.init = function (config) {

        console.log(config);
        this.params = {};

        console.log('config.speed',config.speed);
        // 公告控件ID
        BusNotice.params.noticedomid = config.noticedomid;
        BusNotice.params.speed = config.speed;
        BusNotice.params.direction = config.direction;
        BusNotice.params.resources = [];
        BusNotice.params.regioncode = config.regioncode;
        BusNotice.params.width = "300px";
        BusNotice.params.height = "200px";
        BusNotice.params.content = "";
        BusNotice.loadresource();
    };

    /**
     * 加载公告资源
     */
    BusNotice.loadresource = function () {
        var data = null;

        if (noticejson != null && noticejson.length > 0) {

            // 筛选本区域数据
            for (var i = 0; i < noticejson.length; i++) {
                if (BusNotice.params.regioncode == noticejson[i].regioncode) {
                    data = noticejson[i];
                }
            }

            if (data != null && data.resources != null && data.resources.length > 0) {
                BusNotice.params.resources = data.resources;
            }

            // console.log('公告资源',BusNotice.params.resources);
            if (BusNotice.params.resources != null && BusNotice.params.resources.length > 0) {
                for (var i = 0; i < BusNotice.params.resources.length; i++) {
                    BusNotice.params.content += "<span style='margin-left:80px'>" + BusNotice.params.resources[i].data.content + "</span>";
                }
            }
        }
        else {
            console.log('媒体资源无效');
        }
    }

    /**
     * 播放公告
     */
    BusNotice.play = function () {

        var content = BusNotice.params.content;


        // console.log('BusNotice.params.speed',BusNotice.params.speed);
        $('#' + BusNotice.params.noticedomid).html(content);
        $('#' + BusNotice.params.noticedomid).marquee({
            duration: BusNotice.params.speed * 1000,
            duplicated: false,
        });
    }


})(window);


